package com.tmall.tmall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tmall.tmall.mapper.SlideshowMapper;
import com.tmall.tmall.pojo.PageRt;
import com.tmall.tmall.pojo.Slideshow;
import com.tmall.tmall.pojo.User;
import com.tmall.tmall.service.SlideshowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class SlideshowServiceImpl implements SlideshowService {
    @Autowired
    private SlideshowMapper slideshowMapper;

    @Override
    public void insert(Slideshow slideshow) {
        slideshowMapper.insert(slideshow);
    }

    @Override
    public PageRt page(Integer pageNum, Integer pageSize, String title) {
        PageHelper.startPage(pageNum, pageSize);
        List<Slideshow> list = slideshowMapper.page(title);
        PageInfo<Slideshow> pageInfo = new PageInfo<>(list);
        return new PageRt(pageInfo.getTotal(), pageInfo.getList());
    }

    @Override
    public void update(Slideshow slideshow) {
        slideshowMapper.update(slideshow);
    }

    @Override
    public void delete(List<Integer> ids) {
        for (Integer id : ids) {
            Slideshow slideshow = Slideshow.builder().id(id).deleteAt(LocalDateTime.now()).build();
            slideshowMapper.update(slideshow);
        }
    }

    @Override
    public List<Slideshow> selectAll() {
        return slideshowMapper.selectAll();
    }
}
